<template>
	<view>
		<!-- 自定义导航栏 -->
		<uni-nav-bar :statusBar="true" left-icon="arrowleft" rightText="发布" @click-left="back" @click-right="submit">
			<view class="head-icon" @tap="changelook">
				{{yinsi}}
				<view class="icon iconfont icon-xialazhankai"></view>
			</view>
		</uni-nav-bar>

		<!-- 多行输入框 -->
		<view class="uni-textarea">
			<textarea v-model="text" placeholder="说一句话吧~~" />
			</view>
		
		<!-- 上传多图 -->
		<uploud-images @uploud="uploud"></uploud-images>
		
		<!-- 弹出公告 --> 
		
		<view class="addinput-popup" v-show="showpopup" @hidePopup="hidePopup">
					<view class="gonggao">
						<view class="gonggao-content">
											<image src="../../static/common/addinput.png" mode="widthFix" lazy-load></image>
										</view>
										<view>1.涉及黄色，政治，广告及骚扰信息</view>
										<view>2.涉及人身攻击</view>
										<view>3.留联系方式，泄露他人隐私</view>
										<view>审核将被封禁，情节严重者将永久封禁</view>
										<button type="default" @tap="hidePopup">朕知道了</button>
					</view>
		</view>
		
		
		
		
	</view>
</template>

<script>
	let changelook=['所有人可见', '仅自己可见'];
	import uniNavBar from "../../components/uni-nav-bar/uni-nav-bar.vue"
	import uploudImages from "../../components/common/uploud-images.vue"
	import uniPopup from "../../components/uni-popup/uni-popup.vue"
	
	export default {
		data() {
			return {
				isget:false,
				showpopup:true,
				yinsi:"所有人可见",
				text:"",
				imglist:[]
			}
		},
		onBackPress() {
			// 如果输入框有内容
			if(!this.text && this.imglist.length<1){
				return;
			}
			if (!this.isget) {
				this.baocun();
				return true;
			}
		},
		methods: {
			// 保存为草稿
			baocun(){
				uni.showModal({
					content: '是否要保存为草稿？',
					cancelText: '不保存',
					confirmText: '保存',
					success: res => {
						if ( res.confirm) {
							console.log('保存')
						} else{
							console.log('不保存')
						}
						this.isget=true;
						uni.navigateBack({
							delta: 1
						});
					},
					
				});
			},
			
			// 返回事件
			back(){
				uni.navigateBack({
					delta: 1
				});
			},
			// 发布事件
			submit(){
				console.log("发布")
			},
			// 选择可见
			changelook(){
				uni.showActionSheet({
				    itemList:changelook,
				    success:  (res) => {
				        this.yinsi=changelook[res.tapIndex];
				    }
				});
			},
			uploud(arr){
				this.imglist=arr;
			},
			hidePopup(){
				this.showpopup=false;
			}
		},
		components:{
			uniNavBar,
			uploudImages,
			uniPopup
		}
	}
</script>

<style scoped>
	.head-icon{
		display: flex;
		margin: auto;
	}
	.head-icon .icon{
			margin-left: 10upx;
	}
	.uni-textarea{
		border: 1upx solid #EEEEEE;
	}
	
	.gonggao{
		width: 500upx;
		margin: auto;
		background: #FFFFFF;
		margin-top: 300upx;
		padding: 40upx;
		font-size: 20upx;
	}
	.gonggao image{
		width: 75%;
		margin-bottom: 20upx;
	}
	.gonggao button{
		margin-top: 20upx;
		background: #FFE934;
		color: #171606;
	}
	.addinput-popup{
		position: fixed;
		right: 0;
		left: 0;
		top: 0;
		bottom: 0;
		z-index: 1999;
		background: rgba(51, 51, 51, 0.42);
	}
	
	.gonggao-content{
		text-align: center;
	}

</style>
